home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Disk / moni / FileX-src.lha / FileX-src / filexwindow.c < prev    next >
C/C++ Source or Header  |  1994-04-24  |  21KB  |  915 lines

  1. #include "FileXStructs.h"
  2. #include "FileXStrings.h"
  3. #include "allprotos.h"
  4. #include "WindowInfo.h"
  5.  
  6. struct MsgPort *GadgetReplyPort;
  7.  
  8. void DoGadgetReplyPortMsg( void )
  9. {
  10.     struct Message *Msg;
  11.  
  12.     while( Msg = GetMsg( GadgetReplyPort ))
  13.         FreeVec( Msg );
  14. }
  15.  
  16. BOOL InitReplyPort( void )
  17. {
  18.     if( GadgetReplyPort = CreateMsgPort())
  19.     {
  20.         MyAddSignal( 1 << GadgetReplyPort->mp_SigBit, &DoGadgetReplyPortMsg );
  21.         return( TRUE );
  22.     }
  23.     else
  24.         return( FALSE );
  25. }
  26.  
  27. void FreeReplyPort( void )
  28. {
  29.     struct Message *Msg;
  30.  
  31.     MyRemoveSignal( 1 << GadgetReplyPort->mp_SigBit );
  32.  
  33.     while( Msg = GetMsg( GadgetReplyPort ))
  34.         FreeVec( Msg );
  35.  
  36.     if( GadgetReplyPort )
  37.         DeleteMsgPort( GadgetReplyPort );
  38. }
  39.  
  40. /*
  41.  * static void NewCalcCleanup( struct WindowInfo *wi )
  42.  * 
  43.  * Gibt den durch CalcSetup allokierten Speicher wieder frei.
  44.  */
  45.  
  46. void NewCalcCleanup( struct WindowInfo *wi )
  47. {
  48.     if( wi->TF )
  49.     {
  50.         CloseFont( wi->TF );
  51.  
  52.         wi->TF = NULL;
  53.     }
  54.  
  55.     if( wi )
  56.         FreeMem( wi, sizeof( struct WindowInfo ));
  57. }
  58.  
  59.  
  60. /*
  61.  * struct WindowInfo *NewCalcSetup( struct Screen *Screen )
  62.  * 
  63.  * Ermittelt Werte für die Berechnung.
  64.  */
  65.  
  66. struct WindowInfo *NewCalcSetup( struct Screen *Screen )
  67. {
  68.     struct WindowInfo *wi;
  69.  
  70.     if( wi = AllocMem( sizeof( struct WindowInfo ), MEMF_CLEAR ))
  71.     {
  72.         InitRastPort( &wi->RP );
  73.  
  74.         memcpy(&wi->TA, Screen->Font, sizeof(struct TextAttr));
  75.  
  76.         if( DiskfontBase )
  77.             wi->TF = OpenDiskFont( &wi->TA );
  78.         else
  79.             wi->TF = OpenFont( &wi->TA );
  80.  
  81.         if( wi->TF )
  82.         {
  83.             WORD k, Width;
  84.             UBYTE Char;
  85.  
  86.             SetFont( &wi->RP, wi->TF );
  87.  
  88.             wi->AverageCharWidth = 0;
  89.             wi->MaxCharWidth = 0;
  90.             wi->MaxNumericWidth = 0;
  91.  
  92.             for( k = 0; k < 256; k++ )
  93.             {
  94.                 Char = k;
  95.  
  96.                 Width = TextLength( &wi->RP, &Char, 1 );
  97.  
  98.                 if( Width > wi->MaxCharWidth )
  99.                     wi->MaxCharWidth = Width;
  100.  
  101.                 wi->AverageCharWidth += Width;
  102.             }
  103.  
  104.             wi->AverageCharWidth /= 256;
  105.  
  106.             for( k = '0'; k <= '9'; k++ )
  107.             {
  108.                 Char = k;
  109.  
  110.                 if((Width = TextLength(&wi->RP,&Char,1)) > wi->MaxNumericWidth)
  111.                     wi->MaxNumericWidth = Width;
  112.             }
  113.  
  114.             if((Width = TextLength(&wi->RP," ",1)) > wi->MaxNumericWidth)
  115.                 wi->MaxNumericWidth = Width;
  116.  
  117.             if((Width = TextLength(&wi->RP,",",1)) > wi->MaxNumericWidth)
  118.                 wi->MaxNumericWidth = Width;
  119.  
  120.             if((Width = TextLength(&wi->RP,".",1)) > wi->MaxNumericWidth)
  121.                 wi->MaxNumericWidth = Width;
  122.  
  123.             if(wi->AverageCharWidth > wi->MaxNumericWidth)
  124.                 wi->MaxNumericWidth = wi->AverageCharWidth;
  125.  
  126.             wi->MaxHexWidth = wi->MaxNumericWidth;
  127.  
  128.             for( k = 'a'; k <= 'f'; k++ )
  129.             {
  130.                 Char = k;
  131.  
  132.                 if((Width = TextLength(&wi->RP,&Char,1)) > wi->MaxHexWidth)
  133.                     wi->MaxHexWidth = Width;
  134.             }
  135.  
  136.             for( k = 'A'; k <= 'F'; k++ )
  137.             {
  138.                 Char = k;
  139.  
  140.                 if((Width = TextLength(&wi->RP,&Char,1)) > wi->MaxHexWidth)
  141.                     wi->MaxHexWidth = Width;
  142.             }
  143.         }
  144.         else
  145.         {
  146.             NewCalcCleanup( wi );
  147.             wi = 0;
  148.         }
  149.     }
  150.  
  151.     return( wi );
  152. }
  153.  
  154. /*
  155.  * void SetzeMuster(struct Window *Wnd)
  156.  *
  157.  * Füllt den Windowhintergrund mit einem Muster.
  158.  */
  159.  
  160. void SetzeMuster(struct Window *Wnd)
  161. {
  162.     if(( Wnd->BorderLeft < Wnd->Width - 1 - Wnd->BorderRight ) &&
  163.         ( Wnd->BorderTop < Wnd->Height - 1 - Wnd->BorderBottom ))
  164.     {
  165.         UWORD füllmuster[] = { 0xaaaa, 0x5555 };
  166.  
  167.         SetAPen( Wnd->RPort, 2 );
  168.         SetAfPt( Wnd->RPort, füllmuster, 1 );
  169.  
  170.         RectFill( Wnd->RPort, Wnd->BorderLeft, Wnd->BorderTop, Wnd->Width - 1 - Wnd->BorderRight, Wnd->Height - 1 - Wnd->BorderBottom );
  171.  
  172.         SetAfPt( Wnd->RPort, 0, 0 );
  173.         SetAPen( Wnd->RPort, 1 );
  174.     }
  175. }
  176.  
  177.  
  178. /*
  179.  * void MyFilledDrawBevelBox(struct RastPort *rp,long x,long y,long b,long h,BOOL rec)
  180.  * 
  181.  * Zeichnet eine mit Pen 0 ausgefüllte Bevelbox.
  182.  */
  183.  
  184. void MyFilledDrawBevelBox(struct RastPort *rp,long x,long y,long b,long h,BOOL rec)
  185. {
  186.     DrawBevelBox( rp, x, y, b, h, GT_VisualInfo, VisualInfo, GTBB_Recessed, rec, TAG_DONE );
  187.  
  188.     SetAPen( rp, 0 );
  189.     RectFill( rp, x + 2, y + 1, x + b - 3, y + h - 2 );
  190.     SetAPen( rp, 1);
  191. }
  192.  
  193.  
  194. /*
  195.  * long MyTextLength( struct RastPort *rp, char *ptr)
  196.  * 
  197.  * Ermittelt die Breite in Pixeln einer Zeichenkette(ohne den Unterstrich '_').
  198.  */
  199.  
  200. long MyTextLength( struct RastPort *rp, char *ptr)
  201. {
  202.     long len = 0;
  203.     char text[40];
  204.  
  205.     while(*ptr)
  206.         if(*ptr != '_') text[len++] = *ptr++;
  207.         else ptr++;
  208.  
  209.     return(TextLength(rp, text, len));
  210. }
  211.  
  212. static WORD SpaltenOffsets[ 10 ];
  213.  
  214. /*
  215.  * static long GetWidth(struct MyNewGadget *NewGadget)
  216.  * 
  217.  * Ermittelt die Maximalbreite aller Gadgettitel
  218.  */
  219.  
  220. static long GetWidth( struct MyNewGadget *NewGadget, struct WindowInfo *wi)
  221. {
  222.     WORD MaxWidth = 0, Width, SpaltenBreite = 0;
  223.     WORD InhaltBreite, MaxInhaltBreite = 0;
  224.     int k = 0;
  225.  
  226.     while(NewGadget->Typ)
  227.     {
  228.         if( NewGadget->Pos == GP_NEWCOLUMN )
  229.         {
  230.             SpaltenOffsets[ k++ ] = SpaltenBreite + MaxWidth + ( MaxWidth ? TEXTGADGETX : 0 );
  231.             SpaltenOffsets[ k++ ] = MaxInhaltBreite + MaxWidth + ( MaxWidth ? TEXTGADGETX : 0 );
  232.  
  233.             SpaltenBreite += MaxWidth + INNERGADGETX + MaxInhaltBreite + ( MaxWidth ? TEXTGADGETX : 0 );
  234.  
  235.             MaxWidth = 0;
  236.             MaxInhaltBreite = 0;
  237.         }
  238.  
  239.         switch(NewGadget->Typ)
  240.         {
  241.             case INTEGER_KIND:
  242.             case SLIDER_KIND:
  243.             case HEX_KIND:
  244.             case STRING_KIND:
  245.                 InhaltBreite = Max(NewGadget->MinHexs * wi->MaxNumericWidth + 12, NewGadget->MinChars * wi->AverageCharWidth + 12);
  246.                 Width = MyTextLength(&wi->RP, NewGadget->Title);
  247.                 break;
  248.  
  249.             case CYCLE_KIND:
  250.                 InhaltBreite = Max(NewGadget->MinHexs * wi->MaxNumericWidth + 12, NewGadget->MinChars * wi->AverageCharWidth + 12);
  251.                 Width = MyTextLength(&wi->RP, NewGadget->Title);
  252.                 break;
  253.  
  254.             case CHECKBOX_KIND:
  255.                 InhaltBreite = (wi->TF->tf_YSize + 3) * CHECKBOX_WIDTH / CHECKBOX_HEIGHT;
  256.                 Width = MyTextLength(&wi->RP, NewGadget->Title);
  257.                 break;
  258.  
  259.             case LISTVIEW_KIND:
  260.                 {
  261.                     long Dummy = MyTextLength(&wi->RP, NewGadget->Title);
  262.  
  263.                     InhaltBreite = Max( Dummy, Max(NewGadget->MinHexs * wi->MaxNumericWidth + 12, NewGadget->MinChars * wi->AverageCharWidth + 12));
  264.                     Width = 0;
  265.                 }
  266.                 break;
  267.  
  268.             default:
  269.                 Width = InhaltBreite = 0;
  270.                 break;
  271.         }
  272.  
  273.         if(Width > MaxWidth)
  274.             MaxWidth = Width;
  275.  
  276.         if(InhaltBreite > MaxInhaltBreite )
  277.             MaxInhaltBreite = InhaltBreite;
  278.  
  279.         NewGadget++;
  280.     }
  281.  
  282.     SpaltenOffsets[ k++ ] = SpaltenBreite + MaxWidth + ( MaxWidth ? TEXTGADGETX : 0 );
  283.     SpaltenOffsets[ k ] = SpaltenBreite + MaxInhaltBreite + MaxWidth + ( MaxWidth ? TEXTGADGETX : 0 );
  284.     SpaltenBreite += MaxWidth + MaxInhaltBreite + ( MaxWidth ? TEXTGADGETX : 0 );
  285.  
  286.     return(SpaltenBreite);
  287. }
  288.  
  289.  
  290. /*
  291.  * static long GetButtonWidth(struct MyNewGadget *NewGadget)
  292.  * 
  293.  * Ermittelt die Maximalbreite aller Buttons
  294.  */
  295.  
  296. static long GetButtonWidth(struct MyNewGadget *NewGadget, WORD *ButtonCount, struct WindowInfo *wi)
  297. {
  298.     WORD MaxWidth = -100, Width;
  299.  
  300.     *ButtonCount = 0;
  301.  
  302.     while(NewGadget->Typ)
  303.     {
  304.         if( NewGadget->Typ == BUTTON_KIND )
  305.         {
  306.             ( *ButtonCount )++;
  307.  
  308.             Width = MyTextLength(&wi->RP, NewGadget->Title);
  309.  
  310.             if(Width == 0)
  311.                 Width = -TEXTGADGETX;
  312.  
  313.             if(Width > MaxWidth)
  314.                 MaxWidth = Width;
  315.         }
  316.  
  317.         NewGadget++;
  318.     }
  319.  
  320.     return(MaxWidth + 16);
  321. }
  322.  
  323.  
  324. /*
  325.  * static long GetHeight(struct MyNewGadget *NewGadget)
  326.  * 
  327.  * Ermittelt die Gesamthöhe aller Gadgets in der Bevelbox
  328.  */
  329.  
  330. static long GetHeight(struct MyNewGadget *NewGadget, struct WindowInfo *wi )
  331. {
  332.     WORD Height = 0, MaxHeight = 0;
  333.  
  334.     while(NewGadget->Typ)
  335.     {
  336.         switch(NewGadget->Pos)
  337.         {
  338.             case GP_LEFTBOTTOM:
  339.             case GP_RIGHTBOTTOM:
  340.             case GP_MIDDLEBOTTOM:
  341.                 break;
  342.  
  343.             case GP_NEWCOLUMN:
  344.                 if( Height > MaxHeight )
  345.                     MaxHeight = Height;
  346.                 Height = 0;
  347.  
  348.             default:
  349.                 switch(NewGadget->Typ)
  350.                 {
  351.                     case INTEGER_KIND:
  352.                     case HEX_KIND:
  353.                     case STRING_KIND:
  354.                     case CYCLE_KIND:
  355.                     case BUTTON_KIND:
  356.                         Height += wi->TF->tf_YSize + 6 + INNERGADGETY;
  357.                         break;
  358.                     case SLIDER_KIND:
  359.                         Height += wi->TF->tf_YSize + 2 + INNERGADGETY;
  360.                         break;
  361.                     case CHECKBOX_KIND:
  362.                         Height += wi->TF->tf_YSize + 3 + INNERGADGETY;
  363.                         break;
  364.                     case LISTVIEW_KIND:
  365.                         Height += wi->TF->tf_YSize * ( LISTVIEWLINES + 1 ) + LISTVIEWTEXTGADGETY + LISTVIEWBORDERY + INNERGADGETY;
  366.                         if( !Kick30 ) Height += LISTVIEWBORDERY20;
  367.                         break;
  368.                 }
  369.                 break;
  370.         }
  371.  
  372.         NewGadget++;
  373.     }
  374.  
  375.     if( Height > MaxHeight )
  376.         MaxHeight = Height;
  377.  
  378.     return(MaxHeight - INNERGADGETY);
  379. }
  380.  
  381.  
  382. /*
  383.  * GetUnderlinedKey(UBYTE *String)
  384.  * 
  385.  * Liefert den Buchstaben nach dem '_' oder 0, falls kein '_' vorhanden.
  386.  */
  387.  
  388. UBYTE GetUnderlinedKey(UBYTE *String)
  389. {
  390.     while(*String && (*String != '_')) String++;
  391.  
  392.     if(*String && *(String+1)) return(*(String+1));
  393.     else return(0);
  394. }
  395.  
  396. /*
  397.  * int NewOpenAWindow( struct WindowData *WD, UBYTE *Title );
  398.  */
  399.  
  400. int NewOpenAWindow( struct WindowData *WD, UBYTE *Title )
  401. {
  402.     struct Gadget **Gadgets;
  403.  
  404.     if( !( Gadgets = WD->Gadgets = AllocVec( WD->GadgetZahl * 4+4, MEMF_CLEAR )))
  405.         return( 5L );
  406.  
  407.     if( WD->WI = NewCalcSetup( Scr ))
  408.     {
  409.         struct NewGadget ng;
  410.         struct MyNewGadget *Gad;
  411.         struct Gadget *g;
  412.         WORD MaxWidth, Width, Height, ButtonCount, ButtonWidth, GadgetWidth;
  413.         ULONG GadgetTyp;
  414.         WORD SpaltenNummer = 0;
  415.  
  416.         static struct TagItem SliderTags[9] =
  417.         {
  418.             GTSL_Min, 0,
  419.             GTSL_Max, 0,
  420.             GTSL_Level, 0,
  421.             GTSL_MaxLevelLen, 6,
  422.             GTSL_LevelFormat, (LONG)"%4.ld",
  423.             PGA_Freedom, LORIENT_HORIZ,
  424.             GA_RelVerify, TRUE,
  425.             GTSL_LevelPlace, PLACETEXT_RIGHT,
  426.             TAG_DONE
  427.         };
  428.         
  429.         static struct TagItem Tags[3] =
  430.         {GT_Underscore, '_', GA_Disabled, 0, 0, 0};
  431.         
  432.         static struct TagItem StringTags[4] =
  433.         {GTST_String, 0, GTST_MaxChars, 0, GTST_EditHook, (LONG) 0, TAG_DONE};
  434.         
  435.         static struct TagItem IntegerTags[2] =
  436.         {GTIN_Number, 0, TAG_DONE};
  437.         
  438.         static struct TagItem CheckboxTags[3] =
  439.         {GTCB_Checked, 0, GTCB_Scaled, TRUE, TAG_DONE};
  440.         
  441.         static struct TagItem ListviewTags[4] =
  442.         {GTLV_Labels, 0, GTLV_ShowSelected, 0, GTLV_Selected, 0, TAG_DONE};
  443.  
  444.         static struct TagItem CycleTags[3] =
  445.         {GTCY_Labels, 0, GTCY_Active, 0, TAG_DONE};
  446.  
  447.             /* Falls die Gadgets noch nicht lokalisiert wurden, */
  448.             /* sie lokalisieren */
  449.  
  450.         if( !WD->SchonMalGeoeffnet )
  451.         {
  452.             Gad = WD->NG;
  453.  
  454.             while( Gad->Typ )
  455.             {
  456.                 Gad->Title = GetStr( Gad->Title );
  457.                 Gad->Key = GetUnderlinedKey( Gad->Title );
  458.  
  459.                 if( Gad->Typ == CYCLE_KIND )
  460.                 {
  461.                     char **String = ( char ** ) Gad->CurrentValue;
  462.  
  463.                     while( *String )
  464.                     {
  465.                         *String = GetStr( *String );
  466.                         String++;
  467.                     }
  468.                 }
  469.  
  470.                 Gad++;
  471.             }
  472.         }
  473.  
  474.             /* Breite der Buttons und Anzahl ermitteln */
  475.  
  476.         ButtonWidth = GetButtonWidth(WD->NG, &ButtonCount, WD->WI);
  477.  
  478.             /* Breite des Fensters = */
  479.             /* Maximale Gadgettextbreite */
  480.             /* + maximale Gadgetbreite */
  481.             /* + 2 * BORDERX Pixel für den gefüllten Freiraum */
  482.             /* + 2 * BEVELX Pixel für die Bevelbox */
  483.             /* + 2 * INNERX Pixel für den Freiraum Gadget - Bevelbox */
  484.  
  485.         Width = (MaxWidth = GetWidth(WD->NG,WD->WI)) + 2 * BORDERX + 2 * BEVELX + 2 * INNERX;
  486.  
  487.             /* Falls die Buttons zusammen zu Breit sind, Window/Gadgetbreite */
  488.             /* vergrößern */
  489.  
  490.         if( ButtonCount * ButtonWidth + (ButtonCount - 1) * INNERGADGETX > Width - 2 * BORDERX )
  491.         {
  492.             Width = ButtonCount * ButtonWidth + (ButtonCount - 1) * INNERGADGETX + 2 * BORDERX;
  493.         }
  494.  
  495.             /* Höhe des Fensters = */
  496.             /* Gesamthöhe der Gadgets in der Bevelbox */
  497.             /* + 2 * BORDERY für den gefüllten Freiraum Window - Bevelbox */ 
  498.             /* + 2 * BEVELY Pixel für die Bevelboxhöhe */
  499.             /* + 2 * INNERY für den Freiraum Bevelbox - Gadgets */
  500.             /* + BUTTONY für den Freiraum Buttons - Bevelbox */
  501.             /* + WD->WI->TF->tf_YSize + 6 für die Buttongadgets */
  502.  
  503.         Height = GetHeight(WD->NG,WD->WI) + 2 * BORDERY + 2 * BEVELY + 2 * INNERY + BUTTONY + WD->WI->TF->tf_YSize + 6;
  504.  
  505.         if( !WD->SchonMalGeoeffnet )
  506.         {
  507.             WD->Left = AktuDI->Wnd->LeftEdge + WNDXOPENOFF;
  508.             WD->Top = AktuDI->Wnd->TopEdge + WNDYOPENOFF;
  509.         }
  510.  
  511.         if((WD->Left + Width + Scr->WBorLeft + Scr->WBorRight) > Scr->Width) WD->Left = Scr->Width - Width;
  512.         if((WD->Top + Height + Scr->RastPort.TxHeight + Scr->WBorTop + 1 + Scr->WBorBottom) > Scr->Height) WD->Top = Scr->Height - Height;
  513.  
  514.         if(! (g = CreateContext( &WD->GList )))
  515.             return(1L);
  516.  
  517.         ng.ng_VisualInfo = VisualInfo;
  518.         ng.ng_TextAttr = &WD->WI->TA;
  519.         ng.ng_Flags = PLACETEXT_LEFT;
  520.         ng.ng_TopEdge = Scr->RastPort.TxHeight + Scr->WBorTop + 1 + BEVELY + INNERY + BORDERY;
  521.         ng.ng_GadgetID = 0;
  522.  
  523.         Gad = WD->NG;
  524.  
  525.         while(Gad->Typ)
  526.         {
  527.             GadgetTyp = Gad->Typ;
  528.  
  529.             Tags[1].ti_Data = Gad->Disabled;
  530.  
  531.             switch(Gad->Pos)
  532.             {
  533.                 case GP_LEFTBOTTOM:
  534.                     ng.ng_LeftEdge = Scr->WBorLeft + BORDERX;
  535.                     break;
  536.  
  537.                 case GP_MIDDLEBOTTOM:
  538.                     ng.ng_LeftEdge = Scr->WBorLeft + ( Width - ButtonWidth ) / 2;
  539.                     break;
  540.  
  541.                 case GP_RIGHTBOTTOM:
  542.                     ng.ng_LeftEdge = Scr->WBorLeft + Width - ButtonWidth - BORDERX;
  543.                     break;
  544.  
  545.                 case GP_NEWCOLUMN:
  546.                     SpaltenNummer+=2;
  547.                     ng.ng_TopEdge = Scr->RastPort.TxHeight + Scr->WBorTop + 1 + BEVELY + INNERY + BORDERY;
  548.  
  549.                 default:
  550.                     ng.ng_LeftEdge = Scr->WBorLeft + BORDERX + BEVELX + INNERX + SpaltenOffsets[ SpaltenNummer ]; 
  551.                     break;
  552.             }
  553.  
  554.             GadgetWidth = SpaltenOffsets[ SpaltenNummer + 1 ] - SpaltenOffsets[ SpaltenNummer ];
  555.  
  556.             switch(Gad->Typ)
  557.             {
  558.                 case INTEGER_KIND:
  559.                     ng.ng_Width = GadgetWidth;
  560.                     ng.ng_Height = WD->WI->TF->tf_YSize + 6;
  561.                     ng.ng_Flags = PLACETEXT_LEFT;
  562.  
  563.                     Tags[2].ti_Tag = TAG_MORE;
  564.                     Tags[2].ti_Data = (LONG)IntegerTags;
  565.  
  566.                     IntegerTags[0].ti_Data = Gad->CurrentValue;
  567.  
  568.                     break;
  569.  
  570.                 case HEX_KIND:
  571.                 case STRING_KIND:
  572.                     ng.ng_Width = GadgetWidth;
  573.                     ng.ng_Height = WD->WI->TF->tf_YSize + 6;
  574.                     ng.ng_Flags = PLACETEXT_LEFT;
  575.  
  576.                     Tags[2].ti_Tag = TAG_MORE;
  577.                     Tags[2].ti_Data = (LONG)StringTags;
  578.  
  579.                     StringTags[0].ti_Data = Gad->CurrentValue;
  580.                     StringTags[1].ti_Data = Gad->Max;
  581.  
  582.                     if(Gad->Typ == HEX_KIND)
  583.                         GadgetTyp = STRING_KIND;
  584.  
  585.                     StringTags[2].ti_Tag = GTST_EditHook;
  586.                     StringTags[2].ti_Data = (LONG) &SearchHook;
  587.                     
  588.                     break;
  589.  
  590.                 case SLIDER_KIND:
  591.                     ng.ng_Width = GadgetWidth - 4 * WD->WI->MaxNumericWidth - 7;
  592.                     ng.ng_Height = WD->WI->TF->tf_YSize + 2;
  593.                     ng.ng_Flags = PLACETEXT_LEFT;
  594.  
  595.                     Tags[2].ti_Tag = TAG_MORE;
  596.                     Tags[2].ti_Data = (LONG)SliderTags;
  597.     
  598.                     SliderTags[0].ti_Data = Gad->Min;
  599.                     SliderTags[1].ti_Data = Gad->Max;
  600.                     SliderTags[2].ti_Data = Gad->CurrentValue;
  601.  
  602.                     break;
  603.  
  604.                 case CHECKBOX_KIND:
  605.                     ng.ng_Width = (WD->WI->TF->tf_YSize + 3) * CHECKBOX_WIDTH / CHECKBOX_HEIGHT;
  606.                     ng.ng_Height = WD->WI->TF->tf_YSize + 3;
  607.                     ng.ng_Flags = PLACETEXT_LEFT;
  608.  
  609.                     Tags[2].ti_Tag = TAG_MORE;
  610.                     Tags[2].ti_Data = (LONG)CheckboxTags;
  611.  
  612.                     CheckboxTags[0].ti_Data = Gad->CurrentValue;
  613.  
  614.                     Gad->CurrentValue = Gad->CurrentValue;
  615.  
  616.                     break;
  617.  
  618.                 case BUTTON_KIND:
  619.                     ng.ng_Width = ButtonWidth;
  620.                     ng.ng_Height = WD->WI->TF->tf_YSize + 6;
  621.                     ng.ng_TopEdge = Height + Scr->RastPort.TxHeight + Scr->WBorTop + 1 - ng.ng_Height - BORDERY;
  622.                     ng.ng_Flags = PLACETEXT_IN;
  623.                     Tags[2].ti_Tag = TAG_DONE;
  624.                     break;
  625.  
  626.                 case LISTVIEW_KIND:
  627.                     ng.ng_Width = GadgetWidth;
  628.                     ng.ng_Height = ( WD->WI->TF->tf_YSize * LISTVIEWLINES ) + LISTVIEWBORDERY;
  629.                     if( !Kick30 ) ng.ng_Height += LISTVIEWBORDERY20;
  630.                     ng.ng_TopEdge += WD->WI->TF->tf_YSize + LISTVIEWTEXTGADGETY;
  631.                     ng.ng_Flags = PLACETEXT_ABOVE;
  632.  
  633.                     Tags[2].ti_Tag = TAG_MORE;
  634.                     Tags[2].ti_Data = (LONG) ListviewTags;
  635.  
  636.                     ListviewTags[0].ti_Data = Gad->CurrentValue;
  637.  
  638.                     Gad->CurrentValue = 0;
  639.  
  640.                     break;
  641.  
  642.                 case CYCLE_KIND:
  643.                     ng.ng_Width = GadgetWidth;
  644.                     ng.ng_Height = WD->WI->TF->tf_YSize + 6;
  645.  
  646.                     Tags[2].ti_Tag = TAG_MORE;
  647.                     Tags[2].ti_Data = (LONG) CycleTags;
  648.  
  649.                     CycleTags[0].ti_Data = Gad->CurrentValue;
  650.                     CycleTags[1].ti_Data = Gad->Min;
  651.  
  652.                     Gad->CurrentValue = Gad->Min;
  653.  
  654.                     break;
  655.             }
  656.     
  657.             ng.ng_GadgetText = Gad->Title;
  658.  
  659.             *Gadgets++ = g = CreateGadgetA(GadgetTyp, g, &ng, Tags);
  660.  
  661.             if(!g) return(2L);
  662.  
  663.             g->UserData = Gad;
  664.     
  665.             ng.ng_TopEdge += ng.ng_Height + INNERGADGETY;
  666.             Gad++;
  667.             ng.ng_GadgetID++;
  668.         }
  669.  
  670.         *Gadgets = 0;
  671.  
  672.         if ( ! ( WD->Wnd = OpenWindowTags( NULL,
  673.                     WA_Left,    WD->Left,
  674.                     WA_Top,        WD->Top,
  675.                     WA_InnerWidth,    Width,
  676.                     WA_InnerHeight,    Height,
  677.                     WA_IDCMP,    BUTTONIDCMP|INTEGERIDCMP|TEXTIDCMP|SLIDERIDCMP|IDCMP_INTUITICKS|IDCMP_MOUSEBUTTONS|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  678.                     WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  679.                     WA_Title,    Title,
  680.                     WA_ScreenTitle,    "FileX '94",
  681.                     WA_PubScreen,    Scr,
  682.                     TAG_DONE )))
  683.         return(3L);
  684.     
  685.         SetzeMuster(WD->Wnd);
  686.     
  687.         MyFilledDrawBevelBox((WD->Wnd)->RPort,    (WD->Wnd)->BorderLeft + BORDERX,
  688.                                                             (WD->Wnd)->BorderTop + BORDERY,
  689.                                                             (WD->Wnd)->Width - (WD->Wnd)->BorderRight - (WD->Wnd)->BorderLeft - BORDERX * 2,
  690.                                                             (WD->Wnd)->Height - (WD->Wnd)->BorderBottom - (WD->Wnd)->BorderTop - 2 * BORDERY - WD->WI->TF->tf_YSize - 6 - BUTTONY,
  691.                                                             TRUE);
  692.     
  693.         AddGList(WD->Wnd, WD->GList, 0, -1, 0);
  694.     
  695.         RefreshGadgets(WD->GList, WD->Wnd, 0);
  696.         GT_RefreshWindow(WD->Wnd, NULL);
  697.  
  698.         MyAddWindow( WD );
  699.         BlockMainWindow();
  700.  
  701.         WD->SchonMalGeoeffnet = TRUE;
  702.  
  703.         return(0);
  704.     }
  705.     else
  706.         return(4L);
  707. }
  708.  
  709. /*
  710.  * void NewCloseAWindow( struct WindowData *WD )
  711.  * 
  712.  * Schließ ein Fenster, gib die Gadgets frei und merkt sich die letzte Pos.
  713.  */
  714.  
  715. void NewCloseAWindow( struct WindowData *WD )
  716. {
  717.     ReleaseMainWindow();
  718.  
  719.     MyRemoveWindow( WD );
  720.  
  721.     if( WD->Wnd )
  722.     {
  723.         WD->Left = WD->Wnd->LeftEdge;
  724.         WD->Top = WD->Wnd->TopEdge;
  725.         CloseWindow( WD->Wnd );
  726.         WD->Wnd = NULL;
  727.     }
  728.  
  729.     if( WD->GList )
  730.     {
  731.         FreeGadgets( WD->GList );
  732.         WD->GList = NULL;
  733.     }
  734.  
  735.     if( WD->Gadgets )
  736.     {
  737.         FreeVec( WD->Gadgets );
  738.         WD->Gadgets = NULL;
  739.     }
  740.  
  741.     if( WD->WI )
  742.     {    
  743.         NewCalcCleanup( WD->WI );
  744.         WD->WI = NULL;
  745.     }
  746.     
  747. }
  748.  
  749.  
  750. /*
  751.  * void KeySelect(struct Gadget **GadgetList, struct IntuiMessage *Msg)
  752.  * 
  753.  * Wandelt Tastaturnachrichten in entsprechende andere Nachrichten.
  754.  */
  755.  
  756. void KeySelect(struct Gadget **GadgetList, struct IntuiMessage *Msg)
  757. {
  758.     if(Msg->Class == IDCMP_VANILLAKEY)
  759.     {
  760.             /* Drücken der ESC-Taste ggf. in ein CLOSEWINDOW umwandeln */
  761.  
  762.         if(Msg->Code == '\033' && (Msg->IDCMPWindow -> Flags & WFLG_CLOSEGADGET))
  763.             Msg->Class = IDCMP_CLOSEWINDOW;
  764.         else
  765.         {
  766.             struct MyNewGadget *MyNewGadget;
  767.             BOOL Shift, GotIt = FALSE;
  768.  
  769.                 /* Run down all the gadgets. */
  770.  
  771.             while((!GotIt) && ( *GadgetList ))
  772.             {
  773.                 /* Is there a gadget? */
  774.  
  775.                 MyNewGadget = (*GadgetList)->UserData;
  776.  
  777.                     /* Do the keys match? */
  778.  
  779.                 if(ToUpper(MyNewGadget->Key) == ToUpper(Msg->Code))
  780.                 {
  781.                     GotIt = TRUE;
  782.  
  783.                         /* Groß oder Kleinbuchtabe?
  784.                          * Shift gedrückt?
  785.                          */
  786.  
  787.                     if(ToUpper(MyNewGadget->Key) == Msg->Code)
  788.                         Shift = TRUE;
  789.                     else
  790.                         Shift = FALSE;
  791.  
  792.                         /* Update the object information. */
  793.  
  794.                     switch(MyNewGadget->Typ)
  795.                     {
  796.                         case HEX_KIND:
  797.                         case STRING_KIND:
  798.                         case INTEGER_KIND:
  799.                             ActivateGadget( *GadgetList, Msg->IDCMPWindow, NULL);
  800.  
  801.                             Msg->Class = IDCMP_GADGETDOWN;
  802.                             Msg->Code = 0;
  803.                             Msg->IAddress = *GadgetList;
  804.  
  805.                             break;
  806.  
  807.                         case BUTTON_KIND:
  808.                             Msg->Class = IDCMP_GADGETUP;
  809.                             Msg->Code = 0;
  810.                             Msg->IAddress = *GadgetList;
  811.  
  812.                             break;
  813.  
  814.                         case CHECKBOX_KIND:
  815.                             GT_SetGadgetAttrs( *GadgetList, Msg->IDCMPWindow, NULL,
  816.                                 GTCB_Checked,    MyNewGadget->CurrentValue ? FALSE : TRUE,
  817.                             TAG_DONE);
  818.  
  819.                             Msg->Class = IDCMP_GADGETUP;
  820.                             Msg->IAddress = *GadgetList;
  821.  
  822.                             break;
  823.  
  824.                         case SLIDER_KIND:
  825.                             if(!Shift)
  826.                             {
  827.                                 if(MyNewGadget->CurrentValue < MyNewGadget->Max)
  828.                                 {
  829.                                     GT_SetGadgetAttrs( *GadgetList, Msg->IDCMPWindow, NULL,
  830.                                         GTSL_Level,    MyNewGadget->CurrentValue + 1,
  831.                                     TAG_DONE);
  832.  
  833.                                     Msg->Class = IDCMP_MOUSEMOVE;
  834.                                     Msg->Code = MyNewGadget->CurrentValue + 1;
  835.                                     Msg->IAddress = *GadgetList;
  836.                                 }
  837.                             }
  838.                             else
  839.                             {
  840.                                 if(MyNewGadget->CurrentValue > MyNewGadget->Min)
  841.                                 {
  842.                                     GT_SetGadgetAttrs(*GadgetList, Msg->IDCMPWindow, NULL,
  843.                                         GTSL_Level,    MyNewGadget->CurrentValue - 1,
  844.                                     TAG_DONE);
  845.  
  846.                                     Msg->Class = IDCMP_MOUSEMOVE;
  847.                                     Msg->Code = MyNewGadget->CurrentValue - 1;
  848.                                     Msg->IAddress = *GadgetList;
  849.                                 }
  850.                             }
  851.  
  852.                             break;
  853.  
  854.                         case LISTVIEW_KIND:
  855.                             if(!Shift)
  856.                             {
  857.                                 if(MyNewGadget->CurrentValue < MyNewGadget->Max)
  858.                                 {
  859.                                     GT_SetGadgetAttrs( *GadgetList, Msg->IDCMPWindow, NULL,
  860.                                         GTLV_Selected, MyNewGadget->CurrentValue + 1,
  861.                                         GTLV_Top, MyNewGadget->CurrentValue + 1,
  862.                                         GTLV_MakeVisible, MyNewGadget->CurrentValue + 1,
  863.                                     TAG_DONE);
  864.                         
  865.                                     Msg->Class = IDCMP_GADGETUP;
  866.                                     Msg->Code = MyNewGadget->CurrentValue + 1;
  867.                                     Msg->IAddress = *GadgetList;
  868.                                 }
  869.                             }
  870.                             else
  871.                             {
  872.                                 if(MyNewGadget->CurrentValue > 0)
  873.                                 {
  874.                                     GT_SetGadgetAttrs( *GadgetList, Msg->IDCMPWindow, NULL,
  875.                                         GTLV_Selected, MyNewGadget->CurrentValue - 1,
  876.                                         GTLV_Top, MyNewGadget->CurrentValue - 1,
  877.                                         GTLV_MakeVisible, MyNewGadget->CurrentValue - 1,
  878.                                     TAG_DONE);
  879.                         
  880.                                     Msg->Class = IDCMP_GADGETUP;
  881.                                     Msg->Code = MyNewGadget->CurrentValue - 1;
  882.                                     Msg->IAddress = *GadgetList;
  883.                                 }
  884.                             }
  885.  
  886.                             break;
  887.  
  888.                         case CYCLE_KIND:
  889.                             if( !Shift )
  890.                             {
  891.                                 GT_SetGadgetAttrs( *GadgetList, Msg->IDCMPWindow, NULL,
  892.                                     GTCY_Active, Msg->Code = ( MyNewGadget->CurrentValue == MyNewGadget->Max ) ? 0 : MyNewGadget->CurrentValue + 1,
  893.                                 TAG_DONE);
  894.                             }
  895.                             else
  896.                             {
  897.                                 GT_SetGadgetAttrs( *GadgetList, Msg->IDCMPWindow, NULL,
  898.                                     GTCY_Active, Msg->Code = MyNewGadget->CurrentValue ? MyNewGadget->CurrentValue - 1 : MyNewGadget->Max,
  899.                                 TAG_DONE);
  900.                             }
  901.  
  902.                             Msg->Class = IDCMP_GADGETUP;
  903.                             Msg->IAddress = *GadgetList;
  904.  
  905.                             break;
  906.                     }
  907.                 }
  908.  
  909.                 GadgetList++;
  910.             }
  911.         }
  912.     }
  913. }
  914.  
  915.